package org.techmore.bussiness;

import org.techmore.dataaccessobject.ChallengeMainActivityDAO;

import android.content.Context;
import android.os.Handler;

public class ChallengeMainActivityDataHandler {

	private static ChallengeMainActivityDataHandler challengeMainActivityDataHandler = new ChallengeMainActivityDataHandler();

	public static ChallengeMainActivityDataHandler getInstance() {
		return challengeMainActivityDataHandler;
	}

//	private List<Integer> numList = null;
	private QuestionsBeanDataHandler questionsBeanDataHandler = null;
	private ChallengeMainActivityDAO challengeMainActivityDAO = null;
	
	public void initQuestionList(Context context,Handler handler) {
		challengeMainActivityDAO = new ChallengeMainActivityDAO();
		
//		String valueStr = initNumList();
		
		questionsBeanDataHandler = QuestionsBeanDataHandler.getInstance();
		questionsBeanDataHandler.clearQuestions();
		
		boolean success = challengeMainActivityDAO.setQuestionListContent(context);
		
		if(success){
			handler.sendEmptyMessage(1);
		}
	}

//	private String initNumList() {
//		StringBuffer stringBuffer = new StringBuffer();
//		numList = new ArrayList<Integer>();
//		numList.clear();
//		Random random = new Random(new Date().getTime());
//		for(int i=0;i<30;i++){
//			Integer k = checkNum(numList,random,getRandomNum(random));
//			numList.add(k);
//			stringBuffer.append(k).append(",");
//		}
////		System.out.println(stringBuffer.substring(0, stringBuffer.length()-1));
//		return stringBuffer.substring(0, stringBuffer.length()-1);
//	}
//
//	private int checkNum(List<Integer> numList, Random random, int num) {
//
//		int k = 0;
//		if (numList.contains(num) || num == 0) {
//			k = checkNum(numList, random, getRandomNum(random));
//		} else {
//			k = num;
//		}
//
//		return k;
//	}
//
//	private int getRandomNum(Random random) {
//		return (int) (random.nextFloat() * 40);
//	}

}
